package powerdev.servlet;

import java.io.IOException;
import java.sql.Date;
import java.sql.Time;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import powerdev.excepcion.DAOExcepcion;
import powerdev.modelo.Persona;
import powerdev.negocio.GestionAlquiler;

/**
 * Servlet implementation class RegistrarLocal
 */
public class RegistrarAlquiler extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegistrarAlquiler() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		GestionAlquiler neg=new GestionAlquiler();
		
		Date fe_Dia=Date.valueOf(request.getParameter("Txt_Fecha"));
		Time nu_HoraI =Time.valueOf(request.getParameter("Txt_HoraI"));
		Time nu_HoraF =Time.valueOf(request.getParameter("Txt_HoraI"));
		Integer codCancha=Integer.parseInt(request.getParameter("Txt_CodCancha"));
		
		HttpSession sesion = request.getSession();
		Persona p = (Persona)sesion.getAttribute("USUARIO_ACTUAL"); 
		
/*		String b=request.getParameter("txtDireccion");
		Integer c=Integer.parseInt(request.getParameter("cboDistrito"));
		String d=request.getParameter("txtDireGoo");
		String e=request.getParameter("txtTelefono");   */
		
		try {
			neg.insertarAlquiler(Date.valueOf("2012-03-18"), Time.valueOf("18:00:00"), Time.valueOf("19:00:00"), Double.valueOf(90), Double.valueOf(0), Double.valueOf(90), false, 1, 1, true);
			//neg.insertarAlquiler(fe_Dia, nu_HoraI,nu_HoraF, Double.valueOf(25), Double.valueOf(0), Double.valueOf(25), true, codCancha, p.getCo_Persona(), true);
			
			request.setAttribute("MENSAJE", "Se registro correctamente.");
			
		} catch (DAOExcepcion e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			request.setAttribute("MENSAJE", e1.getMessage());
		}

		RequestDispatcher rd = request
				.getRequestDispatcher("Alquiler.jsp");
		rd.forward(request, response);
		
	}
	
	

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
